package com.cdsxt;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.context.annotation.FilterType;

import com.cdsxt.genCode.listenner.InitModuleQueryUrlToServletContextListenner;

/**
 * 
 * @author 成都尚学堂 & mr zeng
 * 客服热线：028-65176856
 * 网址： www.cd-sxt.com
 * 
 * @param <PoCls>传入当前dao层对应的po类型
 */
@SuppressWarnings("deprecation")
@SpringBootApplication
@MapperScan({
	"com.cdsxt.dao",
	"com.cdsxt.genCode.dao"
})//如果mybatis面向接口开发需要这里扫描对应的接口的包--dao或mapper。。。
//利用正则排除自动代码生成的包的类
@ComponentScan(
excludeFilters={
    @Filter(type=FilterType.REGEX,pattern="com\\.cdsxt\\.genCode\\.main\\..*")
})
public class GenCodeManageApplication extends WebMvcConfigurerAdapter implements
ServletContextInitializer {

	public static void main(String[] args) {
		SpringApplication.run(GenCodeManageApplication.class, args);
	}
	
	
	@Override
    public void addViewControllers(ViewControllerRegistry registry) {
       registry.addRedirectViewController("/","/views/page/index.jsp");
       super.addViewControllers(registry);
    }
	
	//#配置hibernate则不采用表中列驼峰命名转换
	//1）application.properties要配置
	//2）xxxapplication要配置
//	@Bean
//	public PhysicalNamingStrategy PhysicalNamingStrategyStandardImpl() {
//		return new PhysicalNamingStrategyStandardImpl();
//	}
//	
	
	/**
	 * 
	 * 1）操作hibernate解决懒加载问题！
	 * 2）自动代码模块初始化
	 */
	@Override
	public void onStartup(ServletContext servletContext)
			throws ServletException {
		servletContext.addListener(new InitModuleQueryUrlToServletContextListenner());
	}
}
